package com.rao.gmall.model.cart;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.rao.gmall.model.activity.CouponInfo;
import com.rao.gmall.model.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.rao.gmall.model.product.SkuInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(description = "购物车")
public class CartInfo extends BaseEntity {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户id")
    private String userId;

    @ApiModelProperty(value = "skuid")
    private Long skuId;

    @ApiModelProperty(value = "放入购物车时价格")
    private BigDecimal cartPrice;

    @ApiModelProperty(value = "数量")
    private Integer skuNum;

    @ApiModelProperty(value = "图片文件")
    private String imgUrl;

    @ApiModelProperty(value = "sku名称 (冗余)")
    private String skuName;

    @ApiModelProperty(value = "订单价格")
    private BigDecimal orderPrice;

    @ApiModelProperty(value = "isChecked")
    private Integer isChecked = 1;

    //  ,fill = FieldFill.INSERT
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp createTime;

    //  ,fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp updateTime;

    // 实时价格 skuInfo.price
    BigDecimal skuPrice;

    //  优惠券信息列表（功能阉割）
//    @ApiModelProperty(value = "购物项对应的优惠券信息")
//    private List<CouponInfo> couponInfoList;

    // 将 skuInfo 转换未 CartInfo
    public static CartInfo skuInfoToCartInfo(SkuInfo info){

        CartInfo cartInfo = new CartInfo();
        // 将 skuInfo 参数写入 cartInfo 中
        cartInfo.setId(info.getId());
        cartInfo.setCartPrice(info.getPrice());
        cartInfo.setSkuName(info.getSkuName());
        cartInfo.setSkuId(info.getId());
        // 1：代表被选中，0：表示未选中
        cartInfo.setIsChecked(1);
        cartInfo.setImgUrl(info.getSkuDefaultImg());
        cartInfo.setCreateTime(new Timestamp(new Date().getTime()));
        cartInfo.setUpdateTime(new Timestamp(new Date().getTime()));
        // 返回 cartInfo 对象
        return cartInfo;
    }
}
